#include <iostream>
#include <vector>
using namespace std;

int main() {
    int T;
    cin >> T;
    while (T--) {
        int n, q;
        cin >> n >> q;
        vector<int> a(n);
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
        }

        vector<int> isGood(n, 0);
        for (int i = 0; i < n; ++i) {
            if (a[i] % 2 == 0) {
                isGood[i] = 1; // Even number is always good
            }
        }

        // Prefix sum to count good numbers in each range
        vector<int> prefixSum(n + 1, 0);
        for (int i = 1; i <= n; ++i) {
            prefixSum[i] = prefixSum[i - 1] + isGood[i - 1];
        }

        while (q--) {
            int l, r;
            cin >> l >> r;
            cout << prefixSum[r] - prefixSum[l - 1] << endl;
        }
    }
    return 0;
}
